#!/bin/bash
#Please ensure your account has enough privileges before executes the script 
#define alfresco root

if [ "x" = "x$1" ]; then
   echo -e "\nERROR: Invalid arguments"
   echo -e "--------------------------------------------------"
   echo -e "Using: $0 <<Alfresco Installation Directory>>"
   echo -e "eg: $0 /opt/alfesco-3.4"
   echo -e "--------------------------------------------------"
   exit 1
fi

target_dir=$1/tomcat/webapps/

if ! [ -e $target_dir ]; then
   echo -e "\nERROR: Target directory ${target_dir} does not exist.\n"
   exit 1   
fi

#define and test source directory
source_dir=./

if ! [ -e $source_dir ]; then
   echo -e "\nERROR: No language pack found, please check it.\n"
   exit 1
fi

echo -e "\n-------------------- Starting --------------------"

# Find all language files and copy the file to certain folder
for zhtw_file in $(find $source_dir -name "*_zh_TW.properties")
do
   echo -e "\nCopying file \"${zhtw_file}\" to \"${zhtw_file//$source_dir/$target_dir}\""
   cp $zhtw_file ${zhtw_file//$source_dir/$target_dir}
done

# Make a copy to tomcat/shared folder
#echo -e "\nCopying files (*zh_TW.properties) of $target_dir/alfresco/WEB-INF/classes/alfresco/messages to $1/tomcat/shared/classes/alfresco/messages"
#cp $target_dir/alfresco/WEB-INF/classes/alfresco/messages/*zh_TW.properties $1/tomcat/shared/classes/alfresco/messages/
#if ! [ -e $1/tomcat/shared/classes/alfresco/workflow ]; then   
#   mkdir -p $1/tomcat/shared/classes/alfresco/workflow
#   echo -e "\nCreated directory: $1/tomcat/shared/classes/alfresco/workflow"
#fi

#echo -e "\nCopying files (*zh_TW.properties) of $target_dir/alfresco/WEB-INF/classes/alfresco/workflow/ to $1/tomcat/shared/classes/alfresco/workflow"
#cp $target_dir/alfresco/WEB-INF/classes/alfresco/workflow/*zh_TW.properties $1/tomcat/shared/classes/alfresco/workflow

echo -e "\n-------------------- Done --------------------"

